//
const ssr = require('../namespace/SSRLoSNamespace');

var SSRLoSRenderSightLight = cc.Class({
    extends: cc.Component,
    properties: {
        color: {
            default         : cc.color(255, 200, 0, 255),
            displayName     : "color",
            tooltip         : "color",
        },
        intensity: {
            default         : 0.5,
            displayName     : "intensity",
            tooltip         : "intensity",
            min             : 0,
            max             : 1,
        },
        target: {
            default         : null,
            type            : cc.Node
        },
        isIgnoreSourcePosition: {
            default         : true
        },
    },
    onLoad:function() {
        var losCoreComponent = this.target.getComponent("SSRLoSComponentCore");
        if (losCoreComponent) {
            this._losCore = losCoreComponent.getLoSCore();
        }
        //
        var radius = 0;
        var sourceRadius = 0;
        if (this._losCore.getMode() == ssr.LoS.Constant.MODE.UNLIMITED_RANGE) {
            var rect = this._losCore.getSightRect();
            radius = Math.sqrt(rect.width * rect.width, rect.height * rect.height);
            sourceRadius = 10;
        }
        else {
            radius = this._losCore.getRadius() * 1.2;
            sourceRadius = this._losCore.getRadius() * 0.05;
        }
        this._losComponentRenderSightLight = new ssr.LoS.Render.Light(radius, sourceRadius, 0.8);
        this.node._sgNode.addChild(this._losComponentRenderSightLight);
    },
    getRender:function() {
        return this._losComponentRenderSightLight;
    },
    plot:function() {
        if (!this._losCore || !this.node.active) {
            return;
        }
        this._losComponentRenderSightLight.clear();
        this._losComponentRenderSightLight.setCenter(this.target.convertToWorldSpaceAR(cc.p(0, 0)));
        ssr.LoS.Render.Util.renderSightLight(this._losCore, this.getRender(), this.color, this.isIgnoreSourcePosition);
    }
});
